<?php

namespace IDock\Insurance\DAJIA\Response;

use IDock\Http\Response;
use IDock\Insurance\DAJIA\Response\AllDAJIAResponse;
use IDock\Printer\NonCar\NonCarInquirySinglePrinter;
use IDock\Printer\NonCar\NonCarUnderwritingPrinter;
use IDock\Printer\UnderwritingRecallPrinter;
use IDock\Printer\UploadFilePrinter;

/**
 * 非车核保返回
 */
class NonCarUnderWritingResponse extends AllDAJIAResponse
{

    public function printerInit(): Response
    {
        $nonCarUnderwritingPrinter = new NonCarUnderwritingPrinter();

        $this->printer = $nonCarUnderwritingPrinter;

        $data = $this->get('body',[]);
        if(!in_array($data['status'],['0000','2000'])){
            $nonCarUnderwritingPrinter->statusCode = 'error';
            $nonCarUnderwritingPrinter->messageTip = $data['message'];
            $this->setError($data['message']);
            $this->printer = $nonCarUnderwritingPrinter;
            return $this;
        }

        $single = new NonCarInquirySinglePrinter();
        $single->statusCode = 'success';
        $single->inquiryNo = $data['policyInfos'][0]['appNo'] ?? '';
        $single->planCode = $data['policyInfos'][0]['schemeCode'] ?? '';
        $single->productCode = $data['policyInfos'][0]['prodNo'] ?? '';
        $nonCarUnderwritingPrinter->nonCarSingleAppend($single);
        $nonCarUnderwritingPrinter->statusCode = 'success';

        $this->printer = $nonCarUnderwritingPrinter;
        return $this;
    }
}
